package com.tjmc.recruit.user.controller;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tjmc.recruit.common.core.util.R;
import com.tjmc.recruit.common.log.annotation.SysLog;
import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.pig4cloud.plugin.excel.annotation.RequestExcel;
import com.tjmc.recruit.common.security.annotation.Inner;
import com.tjmc.recruit.user.entity.PersonalCollectLogEntity;
import com.tjmc.recruit.user.service.PersonalCollectLogService;

import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import com.tjmc.recruit.common.security.annotation.HasPermission;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * 个人收藏表
 *
 * @author recruit
 * @date 2024-11-11 17:21:06
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/personalCollectLog")
@Tag(description = "personalCollectLog", name = "个人收藏表管理")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class PersonalCollectLogController {

    private final PersonalCollectLogService personalCollectLogService;

    /**
     * 分页查询
     *
     * @param page               分页对象
     * @param personalCollectLog 个人收藏表
     * @return
     */
    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page")
    public R getPersonalCollectLogPage(@ParameterObject Page page, @ParameterObject PersonalCollectLogEntity personalCollectLog) {
        return R.ok(personalCollectLogService.getCollectPage(page, personalCollectLog));
    }


    /**
     * 通过条件查询个人收藏表
     *
     * @param personalCollectLog 查询条件
     * @return R  对象列表
     */
    @Operation(summary = "通过条件查询", description = "通过条件查询对象")
    @GetMapping("/details")
    public R getDetails(@ParameterObject PersonalCollectLogEntity personalCollectLog) {
        return R.ok(personalCollectLogService.list(Wrappers.query(personalCollectLog)));
    }

    /**
     * 新增个人收藏表
     *
     * @param personalCollectLog 个人收藏表
     * @return R
     */
    @Operation(summary = "新增个人收藏表", description = "新增个人收藏表")
    @SysLog("新增个人收藏表")
    @PostMapping
    public R save(@RequestBody PersonalCollectLogEntity personalCollectLog) {
        return R.ok(personalCollectLogService.save(personalCollectLog));
    }

    /**
     * 修改个人收藏表
     *
     * @param personalCollectLog 个人收藏表
     * @return R
     */
    @Operation(summary = "修改个人收藏表", description = "修改个人收藏表")
    @SysLog("修改个人收藏表")
    @PutMapping
    public R updateById(@RequestBody PersonalCollectLogEntity personalCollectLog) {
        return R.ok(personalCollectLogService.updateById(personalCollectLog));
    }

    /**
     * 通过id删除个人收藏表
     *
     * @param ids id列表
     * @return R
     */
    @Operation(summary = "通过id删除个人收藏表", description = "通过id删除个人收藏表")
    @SysLog("通过id删除个人收藏表")
    @DeleteMapping
    public R removeById(@RequestBody Long[] ids) {
        return R.ok(personalCollectLogService.removeBatchByIds(CollUtil.toList(ids)));
    }

    @Operation(summary = "根据职位ID删除", description = "根据职位ID删除")
    @SysLog("根据职位ID删除")
    @DeleteMapping("/removeByJobId")
    @Inner
    public R removeByJobId(@RequestBody Long[] ids) {
        return R.ok(personalCollectLogService.remove(Wrappers.<PersonalCollectLogEntity>lambdaQuery()
                .in(PersonalCollectLogEntity::getJobId, CollUtil.toList(ids))));
    }
}
